package freshmanspecial.mredrock.com.welcomefreshman.View;

import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;

import freshmanspecial.mredrock.com.welcomefreshman.Adapter.MyPagerAdapter;
import freshmanspecial.mredrock.com.welcomefreshman.Base.BaseActivity;
import freshmanspecial.mredrock.com.welcomefreshman.Bean.MilitaryTrainingPhotoBean;
import freshmanspecial.mredrock.com.welcomefreshman.Fragment.Picture;
import freshmanspecial.mredrock.com.welcomefreshman.Model.TrainModel;
import freshmanspecial.mredrock.com.welcomefreshman.R;

/**
 * Created by Administrator on 2017/8/13 0013.
 */

public class PictureView extends BaseActivity {
    private ViewPager viewPager;
    private TextView size,text_position,name;
    private MyPagerAdapter adapter;
    private List<Fragment> list;
    private MilitaryTrainingPhotoBean bean ;
    @Override
    protected void initData() {
        list = new ArrayList<>();
        viewPager = $(R.id.show_picture);
        size = $(R.id.pic_size);
        text_position = $(R.id.pic_position);
        name = $(R.id.pic_name);
        TrainModel trainModel = new TrainModel();
        trainModel.getTrainingPhoto(new TrainModel.OnGetTrain() {
            @Override
            public void onFinish(Object dataBean) {
                bean = (MilitaryTrainingPhotoBean) dataBean;
                for(int i=0;i<bean.getData().getTitle().size();i++){
                    list.add(new Picture(bean.getData().getUrl().get(i)));
                }
                adapter = new MyPagerAdapter(getSupportFragmentManager());
                adapter.setFragments(list);
                adapter.setTitles(null);
                viewPager.setAdapter(adapter);
                size.setText("/"+bean.getData().getTitle().size()+"");
                text_position.setText("1");
                name.setText("重邮军魂");
                viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                    @Override
                    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

                    }

                    @Override
                    public void onPageSelected(int position) {
                        text_position.setText(position+1+"");
                        name.setText(bean.getData().getTitle().get(position));
                    }

                    @Override
                    public void onPageScrollStateChanged(int state) {

                    }
                });
            }
        });
    }

    @Override
    protected int getContentViewId() {
        return R.layout.special_2017_pictureview;
    }
}
